# Minimum CMake version required
cmake_minimum_required(VERSION 3.10)

# Project name and version
project(GridTrans VERSION 1.0)

# use Release build type by default
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()

# OpenMP support
find_package(OpenMP REQUIRED)

# C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# Makefile verbose
set(CMAKE_VERBOSE_MAKEFILE ON)

# External libraries
set(GEOGRAM "src/ext/geogram-1.9.2")

if(WIN32)
    include_directories(${GEOGRAM}/include)
    link_directories(${GEOGRAM}/lib)
else()
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -march=native")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -march=native")

    set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto")
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")

    # Fast math optimization
    # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffast-math")
    # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math")

    include_directories(${GEOGRAM}/include)
    link_directories(${GEOGRAM}/lib_linux)
endif()


# fmt package
add_subdirectory("src/ext/fmt-11.1.3")

# Include directories
include_directories(include)

add_executable(GridA 
    src/GridA.cpp 
    src/GRDECLData.cpp 
    src/GeoGrid.cpp 
    src/geo2d.cpp 
    src/geo3d.cpp
    src/mesh3d.cpp
)
target_link_libraries(GridA geogram OpenMP::OpenMP_CXX fmt::fmt)
set_target_properties(GridA PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)

add_executable(GridB 
    src/GridB.cpp 
    src/GRDECLData.cpp 
    src/GeoGrid.cpp 
    src/geo2d.cpp 
    src/geo3d.cpp
    src/mesh3d.cpp
)
target_link_libraries(GridB geogram OpenMP::OpenMP_CXX fmt::fmt)
set_target_properties(GridB PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
